import java.awt.EventQueue;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;

import javax.swing.JOptionPane;


public class DiveComputer {

        protected Shell shell;
        private Table table;
        private Spinner surfacetime;
        private Spinner divedepth;
        private Spinner divetime;
        int[][] diveTime = new int[][]{
                {5, 15, 25, 30, 40, 50, 70, 80, 100, 110, 130, 150},
                {0, 10, 15, 25, 30, 40, 50, 60, 70, 80, 0, 100},
                {0, 10, 15, 20, 25, 30, 40, 50, 55, 60, 0, 80},
                {0, 5, 10, 15, 20, 30, 35, 40, 45, 50, 60, 70},
                {0, 5, 10, 15, 20, 25, 30, 35, 40, 0, 50, 60},
                {0, 5, 10, 12, 15, 20, 25, 30, 0, 40, 0, 50},
                {0, 5, 7, 10, 15, 20, 22, 25, 0, 0, 40, 0},
                {0, 0, 5, 10, 13, 15, 20, 0, 0, 30, 0, 0},
                {0, 0, 5, 10, 12, 15, 0, 0, 25, 30, 0, 0},
                {0, 0, 5, 8, 10, 0, 0, 0, 0, 25, 0, 0}
        };
                       
        double[][] surfaceTime = new double[][]{
                {24.00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {24.00, 3.20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {24.00, 4.49, 1.39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {24.00, 5.48, 2.38, 1.09, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {24.00, 6.34, 3.24, 1.57, 0.54, 0, 0, 0, 0, 0, 0, 0, 0},
                {24.00, 7.05, 3.57, 2.28, 1.29, 0.45, 0, 0, 0, 0, 0, 0, 0},
                {24.00, 7.35, 4.25, 2.58, 1.59, 1.15, 0.40, 0, 0, 0, 0, 0, 0},
                {24.00, 7.59, 4.49, 3.20, 2.23, 1.41, 1.06, 0.36, 0, 0, 0, 0, 0},
                {24.00, 8.21, 5.12, 3.43, 2.44, 2.02, 1.29, 0.59, 0.33, 0, 0, 0, 0},
                {24.00, 8.50, 5.40, 4.02, 3.04, 2.20, 1.47, 1.19, 0.54, 0.31, 0, 0, 0},
                {24.00, 8.58, 5.48, 4.19, 3.21, 2.38, 2.03, 1.35, 1.11, 0.49, 0.28, 0, 0},
                {24.00, 9.12, 6.02, 4.35, 3.36, 2.53, 2.19, 1.49, 1.25, 1.04, 0.45, 0.26, 0},
        };
       
        int[][] nitrogenTime = new int[][]{
                {7, 6, 5, 4, 4, 3, 3, 3, 3, 3},
                {17, 13, 11, 9, 8, 7, 7, 6, 6, 6},
                {25, 21, 17, 15, 13, 11, 10, 10, 9, 8},
                {37, 29, 24, 20, 18, 16, 14, 13, 12, 11},
                {49, 38, 30, 26, 23, 20, 18, 16, 15, 13},
                {61, 47, 36, 31, 28, 24, 22, 20, 18, 16},
                {73, 56, 44, 37, 32, 29, 26, 24, 21, 19},
                {87, 66, 52, 43, 38, 33, 30, 27, 25, 22},
                {101, 76, 61, 50, 43, 38, 34, 31, 28, 25},
                {116, 87, 70, 57, 48, 43, 38, 0, 0, 0},
                {138, 99, 79, 64, 54, 47, 0, 0, 0, 0},
                {161, 111, 88, 72, 61, 53, 0, 0, 0, 0},
        };
        Integer number = 1;
        int depthInput = 0;
        int timeInput = 0;
        double surfaceInput = 0;
        int depthIndex = 0;
        int timeIndex = 0;
        int surfaceIndex = 0;
        char pressureGroup = ' ';
        boolean valid = false;
        int totalNitrogen;
       
       
        /**
         * Launch the application.
         * @param args
         */
        public static void main(String[] args) {
                String [] string;
                string = new String[3];
                string[0] = "1";
                string[1] = "2";
                string[2] = "3";
               
                try {
                        DiveComputer window = new DiveComputer();
                        window.open();
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }

        /**
         * Open the window.
         */
        public void open() {
                Display display = Display.getDefault();
                createContents();
                shell.open();
                shell.layout();
                while (!shell.isDisposed()) {
                        if (!display.readAndDispatch()) {
                                display.sleep();
                        }
                }
        }

        /**
         * Create contents of the window.
         */
        protected void createContents() {
                shell = new Shell();
                shell.setSize(440, 498);
                shell.setText("Dive Computer");
                shell.setLayout(new GridLayout(6, false));
               
                Label lblCheckFieldsCarefully = new Label(shell, SWT.NONE);
                lblCheckFieldsCarefully.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 6, 1));
                lblCheckFieldsCarefully.setText("Check fields carefully before submitting.  Cannot be modified.");
               
                Label lblSurfaceTime = new Label(shell, SWT.NONE);
                lblSurfaceTime.setText("Surface time");
               
                 
                 Spinner hours = new Spinner(shell, SWT.BORDER);
                 hours.setMaximum(24);
                 hours.setMinimum(0);
                 hours.setEnabled(false);
                 
                 Label lblHours = new Label(shell, SWT.NONE);
                 lblHours.setText("hours");
                 
                 surfacetime = new Spinner(shell, SWT.BORDER);
                 surfacetime.setMaximum(59);
                 surfacetime.setEnabled(false);
                 
                 Label lblMinutes = new Label(shell, SWT.NONE);
                 lblMinutes.setText("minutes");
               
                 Button btnSubmitSurfaceTime = new Button(shell, SWT.NONE);
                 btnSubmitSurfaceTime.addMouseListener(new MouseAdapter() {
                         @Override
                         public void mouseDown(MouseEvent e) {
                                 if(surfacetime.isEnabled()){
                                         valid = (hours.getSelection() > 0 || surfacetime.getSelection() > 9);
                                         
                                         if(valid){
                                                 surfaceInput = Double.parseDouble(hours.getText()) + Double.parseDouble(surfacetime.getText())/100;
                                                 surfaceIndex = findSurfaceIndex(surfaceTime, timeIndex, surfaceInput);
                                                 pressureGroup = pressureGroup(surfaceIndex);
                                                 
                                                 //GUI stuff
                                         TableItem tableItem = new TableItem(table, SWT.NONE);
                                         tableItem.setText(0, "---");
                                         tableItem.setText(1, "---");
                                         if(surfacetime.getSelection() > 9){
                                                 tableItem.setText(2, "Surface Time: " + hours.getSelection() + ":" + surfacetime.getSelection() + " hours");
                                                 tableItem.setText(3, "" + pressureGroup);
                                         }
                                         else{
                                                 tableItem.setText(2, "Surface Time: " + hours.getSelection() + ":0" + surfacetime.getSelection() + " hours");
                                                 tableItem.setText(3, "" + pressureGroup);
                                         }
                                         divedepth.setEnabled(true);
                                         divetime.setEnabled(true);
                                         surfacetime.setEnabled(false);
                                         hours.setEnabled(false);
                                         valid = false;
                                         }
                                         else{
                                                 showMessage("Minimum surface time is 10 minutes!");
                                         }
                     
                                 }
                                 else showMessage("Please enter dive information first.");
                         }
                 });
                 btnSubmitSurfaceTime.setText("Submit");
                 
                 Label label_1 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
                 label_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 6, 1));
               
                 Label lblFirstDiveDepth = new Label(shell, SWT.NONE);
                 lblFirstDiveDepth.setText("Dive Depth");
               
                 divedepth = new Spinner(shell, SWT.BORDER);
                 divedepth.setMinimum(1);
                 divedepth.setMaximum(130);
               
                 Label lblFeet = new Label(shell, SWT.NONE);
                 lblFeet.setText("feet");
                 new Label(shell, SWT.NONE);
               
                 Label lblDiveNumber = new Label(shell, SWT.NONE);
                 lblDiveNumber.setText("Dive Number:");
               
                 final Label label = new Label(shell, SWT.NONE);
                 label.setText("1");
               
                 Label lblDiveTime = new Label(shell, SWT.NONE);
                 lblDiveTime.setText("Dive Time");
               
                 divetime = new Spinner(shell, SWT.BORDER);
                 divetime.setMaximum(150);
                 divetime.setMinimum(1);
               
                 Label lblMinutes_1 = new Label(shell, SWT.NONE);
                 lblMinutes_1.setText("minutes");
                 new Label(shell, SWT.NONE);
                 new Label(shell, SWT.NONE);
               
                 Button btnDivetime = new Button(shell, SWT.NONE);
                 btnDivetime.addMouseListener(new MouseAdapter() {
                         @Override
                         public void mouseDown(MouseEvent e) {
                                 if(divetime.isEnabled() ){
                                         if(number == 1){
                                         depthInput = divedepth.getSelection();
                                         depthIndex = findDepthIndex(depthInput);
                                         timeInput = divetime.getSelection();                            
                                         timeIndex = findTimeIndex(diveTime, depthIndex, timeInput);
                                         if(depthInput > 0 && depthInput <= 15){
                                                 showMessage("You are in a safe depth. A safety stop and a break between dives is not required.");
 
                                         }
                                         else{
                                                 valid = safetyStop(depthIndex, timeInput);
                                         
                                                 if(valid){
                                                         pressureGroup = pressureGroup(timeIndex);
                                                         TableItem tableItem = new TableItem(table, SWT.NONE);
                                                         tableItem.setText(0, number.toString());
                                                         tableItem.setText(1, "" + depthInput);
                                                         tableItem.setText(2, "" + timeInput);
                                                         tableItem.setText(3, "" + pressureGroup);
                                                     number++;
                                                     label.setText(number.toString());
                                                     divetime.setEnabled(false);
                                                     divedepth.setEnabled(false);
                                                     surfacetime.setEnabled(true);
                                                     hours.setEnabled(true);
                                                     valid = false;
                                                 }      
                                         }
                                         }
                                         else if(number > 1){
                                                 depthInput = divedepth.getSelection();
                                                 depthIndex = findDepthIndex(depthInput);
                                         
                                         if(nitrogenTime[surfaceIndex][depthIndex] == 0){
                                                 showMessage("WARNING: Diving in this depth while in this pressure group is not allowed.");
                                                                         }
                                         else{
                                                 timeInput = divetime.getSelection();  
                                                 totalNitrogen = timeInput + nitrogenTime[surfaceIndex][depthIndex];
                                                 timeIndex = findTimeIndex(diveTime, depthIndex, totalNitrogen);
                                                 valid = safetyStop(depthIndex, totalNitrogen);

                                             if(valid){
                                                 pressureGroup = pressureGroup(timeIndex);
                                                 TableItem tableItem = new TableItem(table, SWT.NONE);
                                                 tableItem.setText(0, number.toString());
                                                 tableItem.setText(1, "" + depthInput);
                                                 tableItem.setText(2, "" + timeInput);
                                                 tableItem.setText(3, "" + pressureGroup);
                                                 number++;
                                                 label.setText(number.toString());
                                                 divetime.setEnabled(false);
                                                 divedepth.setEnabled(false);
                                                 surfacetime.setEnabled(true);
                                                 hours.setEnabled(true);
                                                 valid = false;
                                             }
                                         }
                                         }                  
                                 }
                                 else showMessage("Please enter a surface time first.");
                         }
                 });
                 btnDivetime.setText("Submit");
               
                 table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
                 GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, true, 6, 1);
                 gd_table.widthHint = 433;
                 gd_table.heightHint = 144;
                 table.setLayoutData(gd_table);
                 table.setHeaderVisible(true);
                 table.setLinesVisible(true);
               
                 TableColumn tblclmnNewColumn = new TableColumn(table, SWT.NONE);
                 tblclmnNewColumn.setWidth(52);
                 tblclmnNewColumn.setText("Dive #");
               
                 TableColumn tblclmnNewColumn_1 = new TableColumn(table, SWT.NONE);
                 tblclmnNewColumn_1.setWidth(91);
                 tblclmnNewColumn_1.setText("Depth(feet)");
               
                 TableColumn tblclmnNewColumn_2 = new TableColumn(table, SWT.NONE);
                 tblclmnNewColumn_2.setText("Time(minutes)");
                 tblclmnNewColumn_2.setWidth(200);
                 
                 TableColumn tblclmnNewColumn_3 = new TableColumn(table, SWT.NONE);
                 tblclmnNewColumn_3.setWidth(87);
                 tblclmnNewColumn_3.setText("Pressure Group");
               
                 Label lblNewLabel = new Label(shell, SWT.NONE);
                 lblNewLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 6, 1));
                 lblNewLabel.setText("PROTOTYPE: Cannot be used to plan real dives.");
               
        }

        /** Displays warning messages if depth input is invalid or find the index of the array the depthInput is in if the depth input is valid */
        public static int findDepthIndex(double depthInput){                            
                // creates an array for depth in feet
                int[] depth = {40, 50, 60, 70, 80, 90, 100, 110, 120, 130};
                               
                // the array length of depth
                int depthArray = 10;
                int depthIndex = 0;
               
                if(depthInput <= 0){
                        showMessage("WARNING: The minimum depth must be greater than 0 ft.");
                }
                else if(depthInput > 130){
                        showMessage("WARNING: The maximum depth is 130 ft.");
                        return 11;
                }
                else{
                        // find the index of the array the depthInput is in
                        for(int i = 0; i < depthArray; i++){
                                if(depthInput <= depth[i]){
                                        return i;
                                }
                        }
                }
                return depthIndex;
        }
       
       

        public static void showMessage(String message) {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    JOptionPane.showMessageDialog(null, message);
                }
            });
        }


       
       
        /** Displays warning messages if dive time input is less than 0 minutes or find the index of the array the timeInput is in if the dive time input is valid */
        public static int findTimeIndex(int[][] diveTime, int depthIndex, double timeInput){
                // the array length of diveTime
                int timeArray = 12;
                int timeIndex = 0;
               
                if(timeInput <= 0){
                        showMessage("WARNING: The minimum dive time must be greater than 0 minutes.");
                }
                else{
                        // find the index of the array the timeInput is in
                        for(int j = 0; j < timeArray; j++){
                                if(timeInput <= diveTime[depthIndex][j]){
                                        return j;
                                }
                        }                      
                }
                return timeIndex;
        }
       
       
        /* Find the pressure group. */
        public static char pressureGroup(int timeIndex){
                char pressureGroup = ' ';
               
                if(timeIndex == 0){
                        pressureGroup = 'A';
                }
                else if(timeIndex == 1){
                        pressureGroup = 'B';
                }
                else if(timeIndex == 2){
                        pressureGroup = 'C';
                }
                else if(timeIndex == 3){
                        pressureGroup = 'D';
                }
                else if(timeIndex == 4){
                        pressureGroup = 'E';
                }
                else if(timeIndex == 5){
                        pressureGroup = 'F';
                }
                else if(timeIndex == 6){
                        pressureGroup = 'G';
                }
                else if(timeIndex == 7){
                        pressureGroup = 'H';
                }
                else if(timeIndex == 8){
                        pressureGroup = 'I';
                }
                else if(timeIndex == 9){
                        pressureGroup = 'J';
                }
                else if(timeIndex == 10){
                        pressureGroup = 'K';
                }
                else if(timeIndex == 11){
                        pressureGroup = 'L';
                }
                return pressureGroup;
        }
       
       
        /**
        * Displays warning messages if dive time input is greater than the maximum dive time and displays the time for a safety stop.
        * @param depthIndex The index of the array the depthInput is in.
        * @param timeInput
        * @return valid to check if the dive time input is valid.
        */
        public static boolean safetyStop(int depthIndex, double timeInput){
                boolean valid = false;
               
                // if depthInput > 15 && depthInput <= 40
                if(depthIndex == 0 && timeInput <= 130){
                        showMessage("A 3 minute safety stop at 15 ft is recommended.");
                        valid = true;
                }
                else if(depthIndex == 0 && timeInput > 130 && timeInput <= 150){
                        showMessage("WARNING: The maximum dive time in this depth is 130 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 5 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 0 && timeInput > 150){
                        showMessage("WARNING: Diving in this depth for this amount of time is not allowed.");
                }
               
                // if depthInput > 40 && depthInput <= 50
                if(depthIndex == 1 && timeInput <= 80){
                        showMessage("A 3 minute safety stop at 15 ft is recommended.");
                        valid = true;
                }
                else if(depthIndex == 1 && timeInput > 80 && timeInput <= 100){
                        showMessage("WARNING: The maximum dive time in this depth is 80 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 5 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 1 && timeInput > 100){
                        showMessage("WARNING: Diving in this depth for this amount of time is not allowed.");
                }
               
                // if depthInput > 50 && depthInput <= 60
                if(depthIndex == 2 && timeInput <= 55){
                        showMessage("A 3 minute safety stop at 15 ft is recommended.");
                        valid = true;
                }
                else if(depthIndex == 2 && timeInput > 55 && timeInput <= 60){
                        showMessage("WARNING: The maximum dive time in this depth is 55 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 5 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 2 && timeInput > 60 && timeInput <= 80){
                        showMessage("WARNING: The maximum dive time in this depth is 55 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 7 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 2 && timeInput > 80){
                        showMessage("WARNING: Diving in this depth for this amount of time is not allowed.");
                }
               
                // if depthInput > 60 && depthInput <= 70
                if(depthIndex == 3 && timeInput <= 45){
                        showMessage("A 3 minute safety stop at 15 ft is recommended.");
                        valid = true;
                }
                else if(depthIndex == 3 && timeInput > 45 && timeInput <= 50){
                        showMessage("WARNING: The maximum dive time in this depth is 45 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 5 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 3 && timeInput > 50 && timeInput <= 60){
                        showMessage("WARNING: The maximum dive time in this depth is 45 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 8 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 3 && timeInput > 60 && timeInput <= 70){
                        showMessage("WARNING: The maximum dive time in this depth is 45 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 14 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 3 && timeInput > 70){
                        showMessage("WARNING: Diving in this depth for this amount of time is not allowed.");
                }
               
                // if depthInput > 70 && depthInput <= 80
                if(depthIndex == 4 && timeInput <= 35){
                        showMessage("A 3 minute safety stop at 15 ft is recommended.");
                        valid = true;
                }
                else if(depthIndex == 4 && timeInput > 35 && timeInput <= 40){
                        showMessage("WARNING: The maximum dive time in this depth is 35 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 5 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 4 && timeInput > 40 && timeInput <= 50){
                        showMessage("WARNING: The maximum dive time in this depth is 35 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 10 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 4 && timeInput > 50 && timeInput <= 60){
                        showMessage("WARNING: The maximum dive time in this depth is 35 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 17 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 4 && timeInput > 60){
                        showMessage("WARNING: Diving in this depth for this amount of time is not allowed.");
                }
               
                // if depthInput > 80 && depthInput <= 90
                if(depthIndex == 5 && timeInput <= 25){
                        showMessage("A 3 minute safety stop at 15 ft is recommended.");
                        valid = true;
                }
                else if(depthIndex == 5 && timeInput > 25 && timeInput <= 30){
                        showMessage("WARNING: The maximum dive time in this depth is 25 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 5 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 5 && timeInput > 30 && timeInput <= 40){
                        showMessage("WARNING: The maximum dive time in this depth is 25 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 7 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 5 && timeInput > 40 && timeInput <= 50){
                        showMessage("WARNING: The maximum dive time in this depth is 25 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 18 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 5 && timeInput > 50){
                        showMessage("WARNING: Diving in this depth for this amount of time is not allowed.");
                }
               
                // if depthInput > 90 && depthInput <= 100
                if(depthIndex == 6 && timeInput <= 22){
                        showMessage("A 3 minute safety stop at 15 ft is recommended.");
                        valid = true;
                }
                else if(depthIndex == 6 && timeInput > 22 && timeInput <= 25){
                        showMessage("WARNING: The maximum dive time in this depth is 22 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 5 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 6 && timeInput > 25 && timeInput <= 40){
                        showMessage("WARNING: The maximum dive time in this depth is 22 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 15 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 6 && timeInput > 40){
                        showMessage("WARNING: Diving in this depth for this amount of time is not allowed.");
                }
               
                // if depthInput > 100 && depthInput <= 110
                if(depthIndex == 7 && timeInput <= 15){
                        showMessage("A 3 minute safety stop at 15 ft is recommended.");
                        valid = true;
                }
                else if(depthIndex == 7 && timeInput > 15 && timeInput <= 20){
                        showMessage("WARNING: The maximum dive time in this depth is 15 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 5 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 7 && timeInput > 20 && timeInput <= 30){
                        showMessage("WARNING: The maximum dive time in this depth is 15 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 7 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 7 && timeInput > 30){
                        showMessage("WARNING: Diving in this depth for this amount of time is not allowed.");
                }
               
                // if depthInput > 110 && depthInput <= 120
                if(depthIndex == 8 && timeInput <= 12){
                        showMessage("A 3 minute safety stop at 15 ft is recommended.");
                        valid = true;
                }
                else if(depthIndex == 8 && timeInput > 12 && timeInput <= 15){
                        showMessage("WARNING: The maximum dive time in this depth is 12 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 5 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 8 && timeInput > 15 && timeInput <= 25){
                        showMessage("WARNING: The maximum dive time in this depth is 12 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 6 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 8 && timeInput > 25 && timeInput <= 30){
                        showMessage("WARNING: The maximum dive time in this depth is 12 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 14 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 8 && timeInput > 30){
                        showMessage("WARNING: Diving in this depth for this amount of time is not allowed.");
                }
               
                // if depthInput > 120 && depthInput <= 130
                if(depthIndex == 9 && timeInput <= 8){
                        showMessage("A 3 minute safety stop at 15 ft is recommended.");
                        valid = true;
                }
                else if(depthIndex == 9 && timeInput > 8 && timeInput <= 10){
                        showMessage("WARNING: The maximum dive time in this depth is 8 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 5 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 9 && timeInput > 10 && timeInput <= 25){
                        showMessage("WARNING: The maximum dive time in this depth is 8 minutes.");
                        showMessage("WARNING: A safety stop at 15 ft for 10 minutes is required.");
                        valid = true;
                }
                else if(depthIndex == 9 && timeInput > 25){
                        showMessage("WARNING: Diving in this depth for this amount of time is not allowed.");
                }
                return valid;
        }
       
       
        /** Displays warning messages if surface interval time input is invalid or find the index of the array the surfaceInput is in if the surface interval time input is valid */
        public static int findSurfaceIndex(double[][]surfaceTime, int timeIndex, double surfaceInput){
                // the array length of surfaceTime
                int surfaceArray = 13;
                int surfaceIndex = 0;
               
                if(surfaceInput < 0.10){
                        showMessage("WARNING: The minimum surface interval time must be greater than or equal to 10 minutes.");
                }
                else if(surfaceInput > 24){
                        showMessage("You are not being placed into a new pressure group since you are safe to have another dive after your break.");
                }
                else{
                        // find the index of the array the surfaceInput is in
                        for(int k = 0; k < surfaceArray; k++){
                                if(surfaceInput > surfaceTime[timeIndex][k]){
                                        return k - 1;
                                }
                        }
                }
                return surfaceIndex;
        }
}

